package com.example.werewolf.utils;

import com.example.werewolf.entity.Player;

import java.util.List;

public class RoleUtils {
    public static Player getTargetPlayer(List<Player> allPlayers, Integer targetNum) {
        return allPlayers.stream()
                .filter(player -> targetNum.equals(player.getId()))
                .findFirst()
                .orElse(null);
    }

    public static List<Player> getRoleplayer(List<Player> players, String role) {
        return players.stream().filter(player -> role.equals(player.getRole())).toList();
    }

    public static Player getKilledPlayer(List<Player> allPlayers) {
        return allPlayers.stream()
                .filter(player -> player.isKilled())
                .findFirst()
                .orElse(null);
    }

    public static List<Player> findActionPlayers(List<Player> players, String playerType) {
        return switch (playerType) {
            case "全体" -> players;
            case "存活玩家" -> players.stream().filter(Player::isAlive).toList();
            case "警下玩家" -> players.stream().filter(p -> !p.isSpeech()).toList();
            default -> players.stream().filter(player -> playerType.equals(player.getRole())).toList();
        };
    }


}
